﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <script type="text/javascript">
        $.ajax({
            url: "../data/system.aspx?method=1003",
            async: false,
            success: function (text) {
                if (text == "no")
                    window.location = "error.html";
                else if (text == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                    var tabs = parent.mini.get("mainTabs");
                    var tab1 = tabs.getTab("tab$mpay");
                    var tab2 = tabs.getTab("tab$1003");
                    tab2.enabled = true;
                    tabs.removeTab(tab1);
                    tabs.activeTab(tab2);
                }
            }
        });

        var str = window.location.search;
        var arr = str.split("=");
        var hrno = arr[1].substr(0, arr[1].indexOf('&'));
    </script>
</head>
<body>
    <div class="mini-toolbar" style="border-bottom: 0;">
        <table>
            <tr>
                <td><div id="comname"></div></td>
                <td>
                    <a class="mini-button" iconcls="icon-search" plain="true" onclick="search();">查询</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-add" plain="true" onclick="addRow()">新增</a>
                    <a class="mini-button" iconcls="icon-remove" plain="true" onclick="delRows()">删除</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" allowresize="true"
            idfield="id" multiselect="true" url="../data/system.aspx?method=GetHrPayList" sizeList="[15,20,50,100]" pageSize="15">
            <div property="columns">
                <div type="checkcolumn">
                </div>
                <div cellCls="actionIcons" name="action" width="60px" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;">操作</div>
                <div field="hr_company" width="150px" headeralign="center" align="center" allowsort="true">
                    单位名称</div>
                <div field="hr_card" width="100px" headeralign="center" align="center" allowsort="true">
                    营业执照号</div>
                <div field="hr_name" width="100px" headeralign="center" align="center" allowsort="true">
                    会员代表姓名</div>
                <div field="hp_money" width="50px" headeralign="center" align="center" allowsort="true">
                    费用(元)</div>
                <div field="hp_memo" headeralign="center" align="center" allowsort="true">
                    备注</div>
                <div field="hp_insertuser" width="50px" headeralign="center" align="center" allowsort="true">
                    添加人</div>
                <div field="hp_inserttime" width="120px" headeralign="center" align="center" allowsort="true" dateFormat="yyyy-MM-dd HH:mm:ss">
                    添加时间</div>
                <div field="hp_insertip" width="70px" headeralign="center" align="center" allowsort="true">
                    添加IP</div>
            </div>
        </div>
    </div>
    <div id="editWindow" class="mini-window" title="会员缴费<span class='red'>( 带 * 号的必须填写)</span>" style="width: 315px;" showmodal="true"
        allowresize="false" allowdrag="true" showFooter="true">
        <div id="editform" class="form">
            <input class="mini-hidden" name="hp_hrno" />
            <input class="mini-hidden" name="hp_name" />
            <table>
                <tr style="height: 20px">
                    <td class="tdtitle" style="width: 20%;">
                        <span class="red">*</span>缴费额：
                    </td>
                    <td class="tdtext">
                        <input name="hp_money" class="mini-textbox" required="true" style="width: 200px;" onvalidation="onMoneyValidation"/><span>元</span>
                    </td>
                </tr>
                <tr>
                    <td class="tdtitle">
                        <span class="red">*</span>备注：
                    </td>
                    <td class="tdtext">
                        <input name="hp_memo" class="mini-textarea" required="true" style="width: 200px; height: 60px;" />
                    </td>
                </tr>
            </table>
        </div>
        <div property="footer" style="text-align:center;padding:5px;">
            <a class="mini-button" style="width:60px;" onclick="updateRow()">保存</a>
            <span style="display:inline-block;width:25px;"></span>
            <a class="mini-button" style="width:60px;" onclick="closewin()">关闭</a>
        </div>
    </div>
    <script type="text/javascript">
        $.ajaxSetup({
            contentType: "application/x-www-form-urlencoded;charset=utf-8",
            complete: function (XMLHttpRequest, textStatus) {
                // 通过XMLHttpRequest取得响应头，sessionstatus
                var sessionstatus = XMLHttpRequest.getResponseHeader("sessionstatus");
                if (XMLHttpRequest.responseText == "out") {
                    var loginWindow = parent.mini.get("loginWindow");
                    if (!loginWindow.visible)
                        loginWindow.show();
                }
            }
        });

        mini.parse();

        $.ajax({
            url: "../data/system.aspx?method=GetHrName",
            async: false,
            data: { id: hrno },
            success: function (text) {
                $("#comname").html("会员：<font color='Blue'>" + text + "</font>");
                mini.getbyName("hp_name").setValue(text);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                ShowMessage("系统提示", "页面加载失败！", 3);
            }
        });

        var grid = mini.get("datagrid1");

        function search() {
            grid.load({ hrno: hrno });
            grid.sortBy("hp_no", "desc");
        }

        function onActionRenderer(e) {
            var record = e.record;
            var uid = record._uid;
            var s = '<span class="icon-remove payspan" title="删除" onclick="delRow(' + uid + ')"></span>';
            return s;
        }

        //新增
        function addRow() {
            var form = new mini.Form("#editform");
            form.clear();
            mini.getbyName("hp_hrno").setValue(hrno);
            var win = mini.get("editWindow");
            if (!win.visible)
                win.show();
        }

        //保存
        function updateRow() {
            var win = mini.get("editWindow");
            var form = new mini.Form("#editform");
            form.validate();
            if (form.isValid() == false)
                return;
            var o = form.getData();
            var json = mini.encode(o);
            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '保存中，请稍后...' });

            $.ajax({
                url: "../data/system.aspx?method=SaveHrPay",
                data: { data: json },
                success: function (ret) {
                    mini.unmask(document.body);
                    if (ret == "out") {
                        var loginWindow = parent.mini.get("loginWindow");
                        if (!loginWindow.visible)
                            loginWindow.show();
                        return;
                    }
                    if (ret > 0) {
                        win.hide();
                        ShowMessage("系统提示", "缴费记录保存成功！", 1);
                        grid.reload();
                    }
                    else if (ret == 0) {
                        win.hide();
                        ShowMessage("系统提示", "该会员已不存在，请确认！", 2);
                        grid.reload();
                    }
                    else
                        ShowMessage("系统提示", "缴费记录保存失败！", 3);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    mini.unmask(document.body);
                    ShowMessage("系统提示", "缴费记录保存失败！", 3);
                }
            });
        }

        //关闭
        function closewin() {
            var win = mini.get("editWindow");
            var form = new mini.Form("#editform");
            form.clear();
            if (win.visible)
                win.hide();
        }

        function delRow(row_uid) {
            var row = grid.getRowByUID(row_uid);
            if (row) {
                mini.confirm("确定删除此缴费记录？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                            $.ajax({
                                url: "../data/system.aspx?method=DeleteHrPay",
                                type: "post",
                                data: { id: row.hp_no },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "缴费记录删除成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "缴费记录删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "缴费记录删除失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
        }

        function delRows() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                mini.confirm("确定删除所选缴费记录？", "系统提示",
                    function (action) {
                        if (action == "ok") {
                            mini.mask({ el: document.body, cls: 'mini-mask-loading', html: '删除中，请稍后...' });
                            var ids = "";
                            for (var i = 0; i < rows.length; i++) {
                                ids += rows[i].hp_no + ',';
                            }

                            $.ajax({
                                url: "../data/system.aspx?method=DeleteHrPay",
                                type: "post",
                                data: { id: ids },
                                success: function (ret) {
                                    mini.unmask(document.body);
                                    if (ret == "out") {
                                        var loginWindow = parent.mini.get("loginWindow");
                                        if (!loginWindow.visible)
                                            loginWindow.show();
                                        return;
                                    }
                                    if (ret >= 0) {
                                        ShowMessage("系统提示", "缴费记录删除成功！", 1);
                                        grid.reload();
                                    }
                                    else
                                        ShowMessage("系统提示", "缴费记录删除失败！", 3);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    mini.unmask(document.body);
                                    ShowMessage("系统提示", "缴费记录删除失败！", 3);
                                }
                            });
                        }
                    }
                );
            }
            else
                ShowMessage("系统提示", "请选择需要删除的缴费记录！", 2);
        }

        //关闭Tab
        function CloseWindow(action) {
            window.CloseOwnerWindow("ok");
            var tabs = parent.mini.get("mainTabs");
            var tab = tabs.getTab("tab$32");
            tab.enabled = true;
            var iframe = tabs.getTabIFrameEl(tab);
            iframe.contentWindow.search();
            tabs.activeTab(tab);
        }
    </script>
</body>
</html>